home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / DISTORT / DIST1_V2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-12-21  |  2.5 KB  |  121 lines

  1. {
  2.  4-waves distortion of a 320x200 bitmap
  3.  by Maple Leaf, 1996
  4.  ------------------------------------------------------------------------
  5.  "version" 2 (AT LEAST four times faster than the previous... ASM RULES!)
  6.  no comments. watch the assembler parts if you want to understand something.
  7.  
  8.  Do whatever you want with this code, but if you intend to use any parts of
  9.  it, please credit me - say "hello Maple Leaf" or something, and this should
  10.  be quite enough...
  11. }
  12.  
  13. uses alloc, dosio, bitmap;
  14.  
  15. var vScr, Temp : word;
  16.     Img : pointer;
  17.     Pal : array[byte] of record r,g,b:byte end;
  18.  
  19.     Wave1, Wave2 : array [0..199] of integer;  { Left/Right }
  20.     Wave3, Wave4 : array [0..319] of integer;  { Up/Down }
  21.  
  22.     SinTab, CosTab : array [byte] of integer;  { sine and cosine }
  23.  
  24.     MaxAmplV, MaxAmplH, AngleIncrement : word;
  25.  
  26. procedure InitVideo;near;assembler;
  27. asm
  28.   mov ax,13h
  29.   int 10h  { init video mode }
  30.   mov dx,3c8h
  31.   mov al,0
  32.   out dx,al
  33.   inc dx
  34.   mov cx,768
  35.   mov si,offset pal
  36.   rep outsb { set palette }
  37. end;
  38.  
  39. procedure vWait;near;assembler;
  40. asm
  41.     mov dx,3DAh
  42. @1: in al,dx
  43.     test al,8
  44.     jne @1
  45. @2: in al,dx
  46.     test al,8
  47.     je @2
  48. end;
  49.  
  50. procedure ShowVScreen;near;assembler;
  51. asm
  52.   push ds
  53.   push es
  54.   mov cx,16000
  55.   mov ax,0A000h
  56.   mov es,ax
  57.   mov di,0
  58.   mov si,di
  59.   mov ds,VScr
  60.   cld
  61.   db 66h; rep movsw
  62.   pop es
  63.   pop ds
  64. end;
  65.  
  66. procedure freeAll;
  67. begin
  68.   free(img);
  69.   hfree(vScr);
  70.   hfree(Temp);
  71. end;
  72.  
  73. procedure InitData;
  74. var k:word;
  75. begin
  76.   vScr:=halloc(64000);
  77.   Temp:=halloc(64000);
  78.   Img:=LoadPCX(paramstr(1),@pal);
  79.   if (Img=nil) or (vScr=0) or (Temp=0) then begin
  80.     freeAll;
  81.     asm mov ax,3; int 10h end;
  82.     writeln('Not enough memory');
  83.     halt
  84.   end;
  85.   for k:=0 to 255 do begin
  86.     SinTab[k]:=trunc(255*sin(k/255*2*pi));
  87.     CosTab[k]:=trunc(255*cos(k/255*2*pi));
  88.   end;
  89. end;
  90.  
  91. procedure UpdateWaves;near;external;
  92. procedure HoriDistort;near;external;
  93. procedure VertDistort;near;external;
  94. {$L distasm}
  95.  
  96. procedure DoIt;
  97. begin
  98.   MaxAmplH:=10; { amplitude of variation (horizontal) }
  99.   MaxAmplV:=4; { amplitude of variation (vertical) }
  100.   AngleIncrement:=5; { this will be the speed of distorsion ... }
  101.   repeat
  102.     UpdateWaves;
  103.     HoriDistort;
  104.     VertDistort;
  105.     vWait;
  106.     ShowVScreen;
  107.   until port[$60]=1;
  108. end;
  109.  
  110. begin
  111.   if paramcount=0 then begin
  112.     writeln('Parameter expected (FileName.PCX)');
  113.     halt
  114.   end;
  115.   InitData;
  116.   InitVideo;
  117.   DoIt;
  118.   asm mov ax,3; int 10h end;
  119.   freeAll;
  120. end.
  121.